package com.jjclub.service.impl;

import com.jjclub.entity.JjclubMenu;
import com.jjclub.entity.JjclubRoleMenu;
import com.jjclub.mapper.JjclubMenuMapper;
import com.jjclub.mapper.JjclubRoleMenuMapper;
import com.jjclub.service.MenuService;
import com.jjclub.util.CommonUtil;
import com.jjclub.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Classname MenuServiceImpl
 * @Description TODO
 * @Date 2019/11/14 9:34
 * @Created by jq
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private JjclubMenuMapper jjclubMenuMapper;

    @Autowired
    private JjclubRoleMenuMapper jjclubRoleMenuMapper;


    @Override
    public List<JjclubMenu> getAllMenus() {
        return jjclubMenuMapper.getAllMenuList();
    }

    @Override
    public ResponseVO addMenu(JjclubMenu menu) {
        ResponseVO responseVO = new ResponseVO();
        try {
            menu.setId(CommonUtil.getKey());
            jjclubMenuMapper.insert(menu);
        }catch (Exception e){
            responseVO.setCode(500);
            responseVO.setMsg(e.getMessage());
        }
        responseVO.setCode(0);
        return responseVO;
    }

    @Override
    public ResponseVO delMenu(String id) {
        ResponseVO responseVO = new ResponseVO();
        jjclubMenuMapper.delMenus(id);
        responseVO.setCode(0);
        responseVO.setMsg("删除成功");
        return responseVO;
    }

    @Override
    public JjclubMenu getJjclubMenuByid(String id) {
        return jjclubMenuMapper.selectByPrimaryKey(id);
    }

    @Override
    public ResponseVO updateMenu(JjclubMenu menu) {
        menu.setCreatetime(new Date());
        ResponseVO responseVO = new ResponseVO();
        jjclubMenuMapper.updateByPrimaryKeySelective(menu);
        responseVO.setCode(0);
        responseVO.setMsg("更新成功");
        return null;
    }

    @Override
    public List<JjclubRoleMenu> getmenusByroleid(String roleid) {
        List<JjclubRoleMenu> jjclubRoleMenuList = jjclubRoleMenuMapper.getAllMenusByroleId(roleid);
        return jjclubRoleMenuList;
    }
}
